package com.example.myblog.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Properties;

/**
 * @Author: Wu YunXia
 * @Description: 发送邮件
 * @Date: Created in 15:59 2020/11/25
 * @Modefied By:
 */

@RestController
public class SendMail {



    @Autowired
    private JavaMailSender mailSender;





public void updatePass(String email,String random){//重置密码


    MimeMessage message = null;
        try {
            message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setFrom("mailxiami@foxmail.com");// 发件人
            helper.setTo(email);// 收件人
            helper.setSubject("标题：修改密码");

            StringBuffer sb = new StringBuffer();
            sb.append("<h3>重置密码</h3>")
                    .append("<div>您的新密码是：</div>"+random);
            helper.setText(sb.toString(), true);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

        mailSender.send(message);




//        SimpleMailMessage message = new SimpleMailMessage();
//        // 收件人
//        message.setTo(email);
//        // 发件人
//        message.setFrom("mailxiami@foxmail.com");
//        // 邮件标题
//        message.setSubject("激活邮件");
////        message("更改密码", "/mail/mail.ftl", admin, data);
//
//        // 邮件内容
////        message.setText("<html><body>" +
////                "<div><input/><input/><button>确定</button></div></body></html>");
//        mailSender.send(message);
        // 抄送人
//        message.setCc("284991289@qq.com");
//        mailSender.send(message);
//
//
//                    message.setText(
//                    "<html>" +
//                            "<body>" + content +
//                            "</body>" +
//                            "</html>", true);
//        步骤 1
//        资源的引用方法：cid:你自己设置的资源ID
//            messageHelper.setText(
//                    "<html>" +
//                            "<body>" +
//                            "<BR>" +
//                            "<div align='center'>" +
//                            "<img src='cid:imageid'/>" +
//                            "<BR>" +
//                            "<h4>" +
//                            "返回 fancydeepin 的Blogjava：" +
//                            "<a href='http://www.blogjava.net/fancydeepin/'>http://www.blogjava.net/fancydeepin/</a>" +
//                            "</h4>" +
//                            "</div>" +
//                            "</body>" +
//                            "</html>", true);
    }

    public void send(String uuid,String email){//激活账号

        SimpleMailMessage message = new SimpleMailMessage();
        // 收件人
        message.setTo(email);
        // 发件人
        message.setFrom("mailxiami@foxmail.com");
        // 邮件标题
        message.setSubject("激活邮件");
        // 邮件内容
        message.setText("点击以下链接激活账号 \n http://116.62.147.89:8089/user/activeEmail?uuid="+uuid);
        // 抄送人
//        message.setCc("284991289@qq.com");
        mailSender.send(message);

    }
}

